*HTML Horizontal Rule*



The <hr> tag in HTML is used to create a horizontal rule, which represents a thematic break between content sections. It is a self-closing tag, meaning it does not require an end tag.


Example



Explanation:

  • <hr> creates a horizontal line across the width of its container.
  • It is a block-level element, meaning it takes up the full width available.
  • By default, it appears as a thin, gray, recessed line.

  • When to Use <hr>

    The <hr> tag is commonly used in the following scenarios:
  • Separating different topics or sections within a document.
  • Creating visual breaks between elements.
  • Structuring long web pages into distinct sections.

  • Example: Separating Sections



    Styling the <hr> Tag with CSS

    The default style of <hr> can be customized using CSS.








    Example using a `div` with a border instead of <hr>


    Best Practices

  • Use <hr> only when indicating a meaningful content break.
  • Use CSS for advanced styling instead of relying on the default browser appearance.
  • Avoid excessive <hr> usage to prevent visual clutter.
  • Consider using padding and margins for spacing instead of <hr> when possible.